package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.SysResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 刘昱江
 * 时间 2021/4/14
 *
 */
@Slf4j
@RestController
@RequestMapping("/file")
//@CrossOrigin
public class FileController {

    @Autowired
    private FileService fileService;

    //http://localhost:8091/file/upload
    @PreAuthorize("hasAuthority('sys:res:create')")
    @PostMapping("/upload")
    public SysResult upload(MultipartFile file){
        log.info("----------------------"+file);

        return fileService.upload(file);
    }

    @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){

        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }
}
